﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edge.Common;
using Edge.Common.Services;
using Edge.Common.Utils;
using Shop.Business.Domain.Catalog;
using Shop.Business.Domain.Customers;
using Shop.Business.Domain.Pricing;

namespace Shop.Business.Domain.Orders.Logic
{
    public class PriceCalculator
    {
        protected ProductGroup group;


        public ProductGroup Group
        {
            get { return group; }
            set { group = value; }
        }

        public PriceCalculator()
        {
        }


        public PriceCalculator(ProductGroup group)
        {
            this.group = group;
        }
//
//        public string GetGroupPrice()
//        {
//            
//            PriceItem ret = new PriceItem();
//            ret.Price = 0;
//            if (group == null)
//                return ret.ToString();
//            foreach (Product prod in group.Products)
//            {
//                PriceCalculator calculator = new PriceCalculator(prod);
//                if (calculator.GetCustomerPrice() != null && calculator.GetCustomerPrice().Price > ret.Price)
//                {
//                    ret = calculator.GetCustomerPrice();
//                }
//            }
//            return ret.ToString();
//        }
//
//        public PriceItem GetCustomerPrice()
//        {
//            PriceItem ret = GetPrice();
//            int discount = 0;
//            if (customer != null)
//                discount = customer.Discount;
//            if (customer != null)
//            {
//                if (product.Group.Category.Discount > 0)
//                {
//                    discount = product.Group.Category.Discount + customer.Discount;
//                    if (discount > 7)
//                        discount = 7;
//                }
//                ret.Price = ret.Price - ret.Price * discount / 100;
//            }
//            else
//                ret = GetPrice();
//            return ret;
//        }
//
//        public int GetProductQty()
//        {
//            int ret = 0;
//            if (product == null)
//                return ret;
//            PriceItemFilter filter = new PriceItemFilter();
//            filter.Product = product;
//            if (Locator.GetService<IPriceItemManager>().Count(filter) == 0)
//                return 0;
//            ICollection<PriceItem> items = Locator.GetService<IPriceItemManager>().Find(FetchOptions.All, filter);
//            foreach (PriceItem item in items)
//            {
//                ret += item.Qty;
//            }
//            return ret;
//        }
    }
}
